package logic;

import data.MovieComputedRating;
import exceptions.ObjectAlreadyInitializedException;
import gui.frmMain;
import gui.pnlAddRating;
import gui.pnlChangeDetails;
import gui.pnlLogin;
import gui.pnlRecommendation;
import gui.pnlRecommendationList;
import gui.pnlRemoveMovie;
import gui.pnlRemoveUser;
import gui.pnlUserPanel;
import gui.pnlUserRegistration;

import javax.swing.JPanel;

public class ToGuiFacade {
	private static ToGuiFacade _facade;

	private frmMain _mainFrame;

	private pnlRemoveMovie _pnlRemoveMovieScreen;

	private pnlRemoveUser _pnlRemoveUserScreen;

	private pnlAddRating _addRatingScreen;

	private pnlChangeDetails _pnlChangeDetails;

	private pnlRecommendationList _pnlRecommendationList;

	private pnlRecommendation _pnlRecommendation;



	private ToGuiFacade(frmMain f){
		_mainFrame = f;

	}
	public static ToGuiFacade getInstance(){
		if (_facade==null){
			_facade = new ToGuiFacade(new frmMain());
		}
		return _facade;
	}

	public static void init(frmMain f) throws ObjectAlreadyInitializedException{
		if (_facade == null){
			_facade = new ToGuiFacade(f);
		}else{
			throw new ObjectAlreadyInitializedException("ToGuiFacade already initialized");
		}
	}
	public void passwordsDontMatch() {
		pnlUserRegistration.setAlertLabel("The passwords given don't match");

	}
	public void missingMandantoryField() {
		pnlUserRegistration.setAlertLabel("Missing mandantory field");

	}
	public void userAlreadyExists() {
		pnlUserRegistration.setAlertLabel("The given username already exists");

	}

	public void changeScreen(JPanel panel){
		_mainFrame.changeScreen(panel);
	}

	public void back(){
		_mainFrame.back();
	}

	public void showMovieScreen(String string, String user){
		_mainFrame.showMovieScreen(string, user);
	}

	public void showUserScreen(String user, boolean isAdmin){
		changeScreen(new pnlUserPanel(user, isAdmin));
		//_mainFrame.showUserScreen(user, isAdmin);
	}
	public void showUserScreenAfterRating(String user, boolean isAdmin) {
		_mainFrame.showUserScreenAfterRating(user , isAdmin);
	}
	public void showLoginErrorScreen(String string) {
		pnlLogin.setAlertLabel(string);
	}
	public void showLoginScreen() {
		_mainFrame.showLoginScreen();
	}
	public void showDeleteUserScreen(String user) {
		_mainFrame.showDeleteUserScreen(user);
	}
	public void showDeleteMovieScreen(String user) {
		_mainFrame.showDeleteMovieScreen(user);
	}
	public void showDeleteMovieMessage() {
		if (_pnlRemoveMovieScreen != null)
			_pnlRemoveMovieScreen.setAlertLabel("Movie succesfully removed");
	}
	public void showDeleteUserMessage() {
		if (_pnlRemoveUserScreen != null)
			_pnlRemoveUserScreen.setAlertLabel("User succesfully removed");
	}
	public void showAddMovieScreen(String user) {
		_mainFrame.showAddMovieScreen(user);

	}
	public void showRecMovies(MovieComputedRating[] recs, int begin) {
		// TODO Auto-generated method stub
		_pnlRecommendation.setMovies(recs, begin);
	}
	
	public void nextTenMoviesToRate(String[] movs, int begin) {
		// TODO Auto-generated method stub
		_pnlRecommendationList.setMovies(movs, begin);
	}
	public void setRemoveMovieScreen(pnlRemoveMovie panel) {
		_pnlRemoveMovieScreen =  panel;

	}
	public void setRemoveUserScreen(pnlRemoveUser panel) {
		_pnlRemoveUserScreen = panel;

	}
	public void setAddRatingScreen(gui.pnlAddRating panel) {
		_addRatingScreen = panel;

	}
	public void setRemoveRatingButton(boolean b) {
		if (_addRatingScreen==null)
			_addRatingScreen.setRemoveRatingBut(b);

	}
	public void setChangeDetailsScreen(pnlChangeDetails cdpanel) {
		_pnlChangeDetails = cdpanel;
		
	}
	public void setRecommendationListScreen(pnlRecommendationList rl) {
		_pnlRecommendationList = rl;
		
	}
	public void setRecommandationPanel(pnlRecommendation pr) {
		_pnlRecommendation = pr;
		
	}
	public void wrongPasswordChange() {
		if (_pnlChangeDetails!=null)
		_pnlChangeDetails.setAlertLabel("Old password is wrong");
	}
	public void passwordsDontMatchOnUserChange() {
		if (_pnlChangeDetails!=null)
			_pnlChangeDetails.setAlertLabel("Passwords dont match");
	}
	public void showUserScreenAfterChangeDetails(String name, boolean admin) {
		_mainFrame.showUserScreenAfterChangeDetails(name, admin);
		
	}
	public void showChangeDetailsScreen(String user) {
		_mainFrame.showChangeDetailsScreen(user);
		
	}
	
}
